package com.health.controller;

import com.health.context.BaseContext;
import com.health.dto.PatientDTO;
import com.health.entity.Order;
import com.health.entity.Patient;
import com.health.result.PageResult;
import com.health.result.R;
import com.health.result.Result;
import com.health.service.OrderService;
import com.health.service.PatientService;
import com.health.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.reactive.ReactiveResourceSynchronization;
import org.springframework.web.bind.annotation.*;

import javax.naming.spi.DirStateFactory;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * 说明：
 *
 * @author XUYINGLIU 2023年03月12日16:18
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @Autowired
    private OrderService orderService;

    /**
     * 就诊人列表
     */
    @GetMapping("/list")
    public Result<List> getById() {
        List<Patient> patientList = patientService.getAll();
        if (patientList != null) {
            return Result.success(patientList);
        }
        return Result.error("未查询到该用户的就诊人信息！");
    }

    /**
     * 删除就诊人
     */
    @PostMapping("/remove")
    public Result delete(Integer patientId) {
        log.info("删除就诊人 id {}", patientId);
        patientService.delete(patientId);
        return Result.success("删除成功");
    }

    /**
     * 获取就诊人信息
     */
    @GetMapping()
    public Result select(Long patientId) {
        Patient patient = patientService.select(patientId);
        log.info("就诊人信息 patient {}", patient.toString());
        return Result.success(patient);
    }

    /**
     * 添加就诊人
     */
    @PostMapping("/save")
    public Result save(@RequestBody PatientDTO dto, Integer patientId) {
        patientService.save(dto, patientId);
        return Result.success();
    }

    //预约记录
    @GetMapping("/by/user")
    public R PatientByUser() {
        log.info("查看预约记录 ：");
        //PageResult list = orderService.list();
        List<Patient> p = patientService.getByUserIdAz();
        return R.success(p);
    }
}
